<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta name="decorator" content="center_common" />
<title>发票信息</title>
<style type="text/css">
em.error {
	height: 25px;
	display: inline-block;
	vertical-align: middle;
	margin-right: 2px;
	margin-left: 20px;
	background: url("${ctxWebStatic}/images/error_img.png") no-repeat 0px
		0px;
	padding-left: 24px;
	color: #d3001e;
	font-size: 16px;
	font-family: "微软雅黑";
}
</style>
<script type="text/javascript">
	var subflag = false;//标识提交状态
	var Modify = false;//如果此状态为true,则勾选框不允许修改。
	var invoiceId = "";
	var that;
	$(function() {
		if ("${resultMessage}" != "") {
			alert("${resultMessage}");
		}
		/* $("#updateForm").validate({
			rules : {
				company : {
					required : true,
					minlength : 5
				},
				address : {
					required : true,
					minlength : 5
				},
				account : {
					required : true,
					minlength : 5
				},
				blank : {
					required : true,
					minlength : 4
				},
				dutyCode : {
					required : true,
					minlength : 10,
				}
			},

			messages : {
				company : {
					required : '请输入企业名称',
					minlength : '请输入5-30个字符'
				},
				address : {
					required : '请输入开票地址',
					minlength : '请输入5-30个字符'
				},
				account : {
					required : '请输入账户',
					minlength : '请输入5-20个字符'
				},
				blank : {
					required : '请输入开户银行',
					minlength : '请输入4-30个字符'
				},
				dutyCode : {
					required : '请输入纳税人识别号',
					minlength : '请输入10-30个字符',
				}
			},

			errorElement : "em",
		});
 */
		validatorUpdate = $("#updateForm").validate({
			onfocusout: function(element) { $(element).valid(); },  
			rules : {
				company : {required : true,companyCheck : true,	rangelength:[5,30]},
				address : {required : true,addressCheck : true,	rangelength:[5,50]},
				account : {required : true,digits : true,rangelength:[5,20]},
				blank : {required : true,blankCheck : true,	rangelength:[4,30]},
				dutyCode : {required : true,dutyCodeCheck:true,	rangelength:[10,30]}
			},
			messages : {
				company : {required : '请输入企业名称',rangelength:'请输入5-30个字符，以汉字或字母开头，可带数字'},
				address : {required : '请输入开票地址',rangelength : '请输入5-50个字符，以汉字开头，可带数字、字母'},
				account : {required : '请输入账户',rangelength : '请输入5-20个数字',digits:'请输入5-20个数字'},
				blank : {required : '请输入开户银行',rangelength : '请输入4-30个字符，以汉字开头，可带数字、字母'},
				dutyCode : {required : '请输入纳税人识别号',rangelength : '请输入10-30个字母或数字'}
			},
			errorContainer: "#messageBox",
			errorPlacement: function(error, element) {
				$("#messageBox").text("输入有误，请先更正。");
				error.insertAfter(element);
			},
			errorElement : "em",
			success:function(lable){
	     		lable.remove(); 
	 		},
		});
		 jQuery.validator.addMethod("companyCheck", function(value,element, param) { 
				var tel = /^[a-zA-Z\u4e00-\u9fa5][a-zA-Z0-9\u4e00-\u9fa5]*$/;  
			 	return this.optional(element) || (tel.test(value));  
		 }, $.validator.format("请输入5-30个字符，以汉字或字母开头，可带数字")); 
		 
		 jQuery.validator.addMethod("addressCheck", function(value,element, param) { 
				var tel = /^[\u4e00-\u9fa5][a-zA-Z0-9\u4e00-\u9fa5]*$/;  
			 	return this.optional(element) || (tel.test(value));  
		 }, $.validator.format("请输入5-50个字符，以汉字开头，可带数字、字母")); 
		 
		 jQuery.validator.addMethod("blankCheck", function(value,element, param) { 
				var tel = /^[\u4e00-\u9fa5][a-zA-Z0-9\u4e00-\u9fa5]*$/;  
			 	return this.optional(element) || (tel.test(value));  
		 }, $.validator.format("请输入4-30个字符，以汉字开头，可带数字、字母")); 
		 
		 jQuery.validator.addMethod("dutyCodeCheck", function(value,element, param) { 
				var tel = /^[a-zA-Z0-9]*$/;  
			 	return this.optional(element) || (tel.test(value));  
		 }, $.validator.format("请输入10-30个字母或数字")); 
		//设为默认
		$(".default_box")
				.click(
						function() {
							if (!Modify) {
								if ($(this).parent().find("i").hasClass(
										"search_chose_hover")) {
									$(this).parent().find("i").removeClass(
											"search_chose_hover");
								} else {
									$(this).parent().find("i").addClass(
											"search_chose_hover");
								}
								var Inputindex = $('.parts_search_list').index(
										$(this));
								$(".numRadio").find('input').eq(Inputindex)
										.click();
							}
						});

		$(".close_page").click(function() {
			$("#proment_new_fptitket").hide();
		});
		
		/*
		$(".js_del").click(function() {
			$("#del_tk").show();
			that = $(this).parents("tr");
		});
		*/

		/*
		$('.submit').on('click', function() {
			$("#del_tk").hide();
			that.remove();
		})
		*/

		//设默认地址
		/*
		$(".js_set").click(
				function() {
					$(this).parents(".table").find(".js_set").removeClass(
							"col_gry ");
					$(this).parents(".table").find(".our_bd").removeClass(
							"our_adress_item ");
					$(this).addClass("col_gry ");
					$(this).parents(".table tr").find(".our_bd").addClass(
							"our_adress_item ");
		});
		 */
	})
	//新增
	function sub() {
		if (subflag) {
			return;
		}
		var checkFlag = true;
		if (!$("#updateForm").valid()) {
			checkFlag = false;
		}
		if (!checkFlag) {
			return false;
		}
		$("#id").val(invoiceId);
		$("#updateForm").submit();
		subflag = true;
	}

	//设置默认
	function setDef(obj, id, isDef) {
		if (isDef == 1) {
			return;
		}
		if (subflag) {
			return;
		}
		subflag = true;
		$.ajax({
			url : "${ctxWeb}/webInvoice/setDef",
			data : {
				"id" : id
			},
			type : "post",
			success : function(data) {
				if (data == "true") {
					$(obj).parents(".table").find(".js_set").removeClass(
							"col_gry ");
					$(obj).parents(".table").find(".our_bd").removeClass(
							"our_adress_item ");
					$(obj).addClass("col_gry ");
					$(obj).parents(".table tr").find(".our_bd").addClass(
							"our_adress_item ");
				} else {

				}
				subflag = false;
			},
			error : function() {
				alert("网络异常");
				subflag = false;
			}
		})
	}

	//弹出新增窗口
	function showAdd() {
		Modify = false;//标识为非修改状态
		validatorUpdate.resetForm();
		invoiceId = "";
		$("#company").val("");
		$("#address").val("");
		$("#account").val("");
		$("#blank").val("");
		$("#dutyCode").val("");
		if ($(".default_box").parent().find("i").hasClass("search_chose_hover")) {
			$(".default_box").parent().find("i").removeClass(
					"search_chose_hover");
		}
		$("#isDef").prop("checked", false);
		$("#proment_new_fptitket").show();
	}

	//弹出修改窗口
	function showModify(id, company, address, account, blank, dutyCode, isDef) {
		validatorUpdate.resetForm();
		invoiceId = id;
		$("#company").val(company);
		$("#address").val(address);
		$("#account").val(account);
		$("#blank").val(blank);
		$("#dutyCode").val(dutyCode);
		if (isDef == 1) {
			if ($(".default_box").parent().find("i").hasClass(
					"search_chose_hover")) {
			} else {
				$(".default_box").parent().find("i").addClass(
						"search_chose_hover");
			}
			Modify = true;
			$("#isDef").prop("checked", true);

		} else {
			if ($(".default_box").parent().find("i").hasClass(
					"search_chose_hover")) {
				$(".default_box").parent().find("i").removeClass(
						"search_chose_hover");
			}
			Modify = false;
			$("#isDef").prop("checked", false);
		}
		$("#proment_new_fptitket").show();
	}
	

	function showDel(obj,id){
		invoiceId = id;
		$("#del_tk").show();
		that = $(obj).parents("tr");
	}
	
	$('.cancle').on('click', function() {
		$("#company").val("");
		$("#address").val("");
		$("#account").val("");
		$("#blank").val("");
		$("#dutyCode").val("");
		$("#del_tk").hide();
	});
	
	function subDel(){
		$.ajax({
			url : "${ctxWeb}/webInvoice/delete",
			data : {
				"id" : invoiceId
			},
			type : "post",
			success : function(data) {
				subflag = false;
				$("#del_tk").hide();
				that.remove();
			},
			error : function() {
				alert("网络异常");
				subflag = false;
			}
		})
	}
</script>
</head>
<body>
	<!-- 右边部分 -->
	<div class="col-sm-10 pad20 pad_10">
		<div class="Credit_right">
			<!--发票信息-->
			<div class="goods_detail_info_box mar_16 clearfix">
				<h3>
					<span>发票信息</span> <a href="javascript:void(0)" class="add_address"
						onclick="showAdd()">+新增</a>
				</h3>
				<!--发票信息表格-->
				<div class="our_adress_box">
					<div class="our_adress_table  clearfix">
						<table class="table table-bordered">
							<thead>
								<tr>
									<th>公司名称</th>
									<th>开票地址</th>
									<th>账户</th>
									<th>开户银行</th>
									<th>是否默认</th>
									<th>纳税人识别号</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${list}" var="bean">
									<tr>
										<td
											class="our_bd <c:if test="${bean.isDef == 1}">our_adress_item</c:if> ">${bean.company}
											<i></i>
										</td>
										<td>${bean.address}</td>
										<td>${bean.account}</td>
										<td>${bean.blank}</td>
										<td
											class="color_red <c:if test="${bean.isDef == 1}">col_gry</c:if> js_set"
											onclick="setDef(this,'${bean.id}')">设置</td>
										<td>${bean.dutyCode}</td>
										<td class="color_blue"><a href="javascript:void(0)"
											class="js_edit"
											onclick="showModify('${bean.id}','${bean.company}','${bean.address}','${bean.account}','${bean.blank}','${bean.dutyCode}','${bean.isDef}')">编辑</a>
											<a href="javascript:void(0)" class="js_del" onclick="showDel(this,'${bean.id}')">删除</a></td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
					</div>
				</div>
				<!--发票信息表格结束-->
			</div>
			<!--发票信息结束-->

		</div>
	</div>
	<!-- 右边部分 end-->
	<!--发票弹框-->
	<div class="jd_tk" id="proment_new_fptitket" style="display: none;">
		<form action="${ctxWeb}/webInvoice/save" id="updateForm" method="post">
			<input type="hidden" id="id" name="id" value="" />
			<div class="address_Bomb">
				<h3 class="address_Bomb_title">
					发票信息 <span class="close_page"> <img
						src="${ctxWebStatic}/images/close.png" alt="" />
					</span>
				</h3>
				<div class="address_Bomb_info clearfix">
					<div class="address_Bomb_left col-sm-9 clearfix">
						<figure class="form-group clearfix">
							<label class="col-sm-3 col-xs-5 fp_lable control-label ">
								公司名称： </label>
							<div class="col-sm-8 col-xs-7 pad0">
								<input type="text" class="form-control" id="company"
									name="company" maxlength="30" placeholder="">
							</div>
						</figure>

						<figure class="form-group clearfix">
							<label class="col-sm-3 col-xs-5 fp_lable control-label ">
								开票地址： </label>
							<div class="col-sm-8 col-xs-7 pad0">
								<div data-toggle="distpicker" class="tk_selcet">
									<!-- container -->
									<input type="text" class="form-control" id="address"
										name="address" maxlength="30" placeholder="">
								</div>
							</div>
						</figure>
						<figure class="form-group clearfix">
							<label class="col-sm-3 col-xs-5 fp_lable control-label ">
								账户： </label>
							<div class="col-sm-8 col-xs-7 pad0">
								<input type="text" class="form-control" id="account"
									name="account" maxlength="20" placeholder="">
							</div>
						</figure>
						<figure class="form-group clearfix">
							<label class="col-sm-3 col-xs-5 fp_lable control-label ">
								开户银行： </label>
							<div class="col-sm-8 col-xs-7 pad0">
								<input type="text" class="form-control" id="blank" name="blank"
									maxlength="30" placeholder="">
							</div>
						</figure>
						<figure class="form-group clearfix">
							<label class="col-sm-3 col-xs-5 fp_lable control-label ">
								纳税人识别号： </label>
							<div class="col-sm-8 col-xs-7 pad0">
								<input type="text" class="form-control" id="dutyCode"
									name="dutyCode" placeholder="">
							</div>
						</figure>
					</div>
					<div class="col-sm-3 default_left">
						<div class="default_box">
							<i class="search_chose"></i> <span>设为默认发票信息</span>
						</div>
						<div class='numRadio' style="display: none;">
							<input type='checkbox' name='isDef' id="isDef" value='1' />
						</div>
					</div>
				</div>
				<div class=" shopping_car_price shopping_car_confirm">
					<a href="javascript:void(0)" onclick="sub()">确认</a>
				</div>
			</div>
		</form>
	</div>
	<!--发票弹框结束-->
	<!--弹框-->
	<div class="jd_tk" id="del_tk" style="display: none;">
		<div class="delet_box">
			<div class="jd_win_tit">你确定删除该商品吗？</div>
			<div class="jd_btn clearfix">
				<a href="javascript:void(0)" class="cancle">取消</a> <a
					href="javascript:void(0)" class="submit" onclick="subDel()">确定</a>
			</div>
		</div>
	</div>
	<!--弹框结束-->
</body>
</html>
